<?php

namespace App\Repositories;

use App\Http\Helper\BeanHelper;
use App\Models\JzNutritionist;
use Cache;
use DB;
class JzNutritionistRepository extends Repository{
    static $tag = 'jz.nutritionist';

    /**获取所有不重复的营养师
     * @return mixed
     */
    public function allName(){
       $key = getCacheKey('testing.cache_key.jznutritionist.allName');
       $list = $this -> remember($key,function(){
           return JzNutritionist::distinct()->pluck('name','name');
       });
       return $list;
    }

    /**
     * 获取营养师信息
     * @param $nutritionId
     * @return mixed
     */
    public function getOneByNutritionId($nutritionId) {
        return BeanHelper::convertStdClsToArr(
            JzNutritionist::where([
                'nutrition_id' => $nutritionId,
            ])->first()
        );
    }

    /**
     * 获取免费流程营养师信息
     * @return mixed
     */
    public function getFreeNutritionList() {
        return BeanHelper::convertStdClsToArr(
            JzNutritionist::where([
                'type' => 0,
            ])->orderBy('sort', 'asc')->get()
        );
    }

    /**
     * 获取付费流程营养师信息
     * @param $nutritionId
     * @return mixed
     */
    public function getPayNutritionList() {
        return BeanHelper::convertStdClsToArr(
            JzNutritionist::where([
                'type' => 1,
            ])->orderBy('sort', 'asc')->get()
        );
    }

    /**
     * 清除读取的缓存
     */
    public function forgetAllName(){
        $key = getCacheKey('testing.cache_key.jznutritionist.allName');
        $this->forget($key);
    }



    public function cacheTime()
    {
        return config('testing.common_cache_time');
    }


    public function model()
    {
        return app(JzNutritionist::class);
    }

    public function tag()
    {
        return self::$tag;
    }
}